


$(function(){
	 if(getvl("code")!=""){
	 	if(sessionStorage.getItem("userIdadmin")!=""){
	 		$("#divs").html("");
	 	selectcode(getvl("code"),sessionStorage.getItem("userIdadmin"));
	 	}else{
	 		alert("超时/请重新登录认证");
	 		window.location.href="gotoindexlogin.html";
	 	}       
	 }
});
//登录
function toLogin(){
	var phone=$("#phone").val();
	var password=$("#password").val();
	if(phone!="" && password!=""){
		$.ajax({
        url:  urlcore + "/api/login/loginPhoneweixinadmin2",
        type: "post",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "phone":phone,
            "password":password
        }),
        dataType: "json",
        success:function(data){
            if (data.success == true) {
					 if(data.data.userType==3 && data.data.adminType==2){
			                window.location.href="gotoindexlogin.html?y=n";				
				 	sessionStorage.setItem("userIdadmin",data.data.id);
					   }else{
                          window.location.href="quanxian.html";					   	  
					   }
             }else{
             	  alert(data.msg);
             	window.location.href="quanxian.html";
            }
        },
        error: function() {
            alert("error");
        }
    });
	}
}

function selectcode(codes,userid){
		$.ajax({
			url: urlcore + "/api/user/getOpenidbings?code="+codes+"&userId="+userid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					 if(data.data.userType==3 && data.data.adminType==2){
					 	alert(JSON.stringify(data.data))
                 	window.location.href="gotoindexlogin.html";
					 }else{
                          window.location.href="quanxian.html";					   	  
					   }
				} else {
				 alert("未绑定微信登录后自动绑定");
                 window.location.href="wx_login.html";
				}
			},
			error: function() {
				alert("error");
			}
		});
}




